package com.avantis.common.repository;

import com.avantis.common.entity.Customer;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

/**
* @Description:    java类作用描述
* @Author:         kirago
* @CreateDate:     2019/1/14 2:17 PM
* @UpdateRemark:   修改内容
* @Version:        1.0
*/
@Repository
public interface CustomerRepository extends JpaRepository<Customer, Integer>,JpaSpecificationExecutor{

    Optional<Customer> findById(String id);

    Customer findByCustomerCode(String customercode);


    @Query(value = "select * from Customer where if(?1 !='',cname=?1, 1=1) and " +
            "if(?2 !='', ccode=?2, 1=1) and if(?3 !='', cphone=?3, 1=1) and" +
            "if(?4 !='', crank=?4, 1=1)", nativeQuery = true)
    List<Customer> searchAll(String cname, String ccode, String cphone, Integer crank);

    @Modifying
    @Query("delete from Customer s where s.id= :id")
    void deleteByUuid(@Param("id")String id);

//    List<Customer> findAll(Sort sort);

}
